package thread;

import javax.swing.plaf.synth.SynthTextAreaUI;

public class Demo10 {
    public static boolean isFinished=false;
    public static void main(String[] args) throws InterruptedException{
       //boolean isFinished =false;
        //lambda是回调函数，执行是很久以后，很有可能线程建好了，main方法也执行完了，才开始这个线程
        Thread t=new Thread(()->{
            while (!isFinished){
                System.out.println("hello thread");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            System.out.println("thread线程结束");
        });
        t.start();
        Thread.sleep(3000);
        isFinished=true;
    }
}
